package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.CodeAssignmentRules;
import com.example.demo.entity.CodingRules;
import com.example.demo.service.CodeAssignmentRulesService;
import com.example.demo.mapper.CodeAssignmentRulesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【code_assignment_rules】的数据库操作Service实现
* @createDate 2024-11-27 17:02:39
*/
@Service
public class CodeAssignmentRulesServiceImpl extends ServiceImpl<CodeAssignmentRulesMapper, CodeAssignmentRules>
    implements CodeAssignmentRulesService{
    @Autowired
    CodeAssignmentRulesMapper codeAssignmentRulesMapper;

    @Override
    public List<CodeAssignmentRules> select(String userId, String appId, String trainingId,String ruleType) {
        QueryWrapper<CodeAssignmentRules> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(appId!=null){
            queryWrapper.eq("appId",appId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }
        if(ruleType!=null){
            queryWrapper.eq("ruleType",ruleType);
        }
        queryWrapper.orderByDesc("id");
        return codeAssignmentRulesMapper.selectList(queryWrapper);
    }

    @Override
    public Integer deleteById(Integer id) {

        return codeAssignmentRulesMapper.deleteById(id);
    }

    @Override
    public CodeAssignmentRules selectById(Integer id) {
        return codeAssignmentRulesMapper.selectById(id);
    }

    @Override
    public Integer deleteByInfo(String userId, String appId, String trainingId) {
        QueryWrapper<CodeAssignmentRules> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        if(appId!=null){
            queryWrapper.eq("appId",appId);
        }
        queryWrapper.eq("trainingId",trainingId);
        queryWrapper.orderByDesc("id");
        return codeAssignmentRulesMapper.delete(queryWrapper);
    }
}




